Using package rgdal we can use the gdal drivers to read ESRI shapefiles. As shapefiles have layers, we need to know which layer to load
library(rgdal)## Loading required package: sp
## rgdal: version: 1.1-3, (SVN revision 594)
## Geospatial Data Abstraction Library extensions to R successfully loaded
## Loaded GDAL runtime: GDAL 1.11.2, released 2015/02/10
## Path to GDAL shared files: /usr/share/gdal/1.11
## Loaded PROJ.4 runtime: Rel. 4.8.0, 6 March 2012, [PJ_VERSION: 480]
## Path to PROJ.4 shared files: (autodetected)
## Linking to sp version: 1.2-1
library(mapview)## Loading required package: leaflet
first we set our working directory
setwd('/home/ede/tappelhans/uni/marburg/lehre/2016/ss/PS_global_change')then we can start working
shp_file <- "data/gadm_deu/gadm_deu.shp"
lyr <- ogrListLayers(dsn = shp_file)
lyr## [1] "gadm_deu"
## attr(,"driver")
## [1] "ESRI Shapefile"
## attr(,"nlayers")
## [1] 1
gadm_deu <- readOGR(dsn = shp_file,
layer = lyr)## OGR data source with driver: ESRI Shapefile
## Source: "data/gadm_deu/gadm_deu.shp", layer: "gadm_deu"
## with 403 features
## It has 15 fields
plot(gadm_deu)
mapview(gadm_deu, color = "blue")## Warning in spCheckObject(x): Columns CCN_2, NL_NAME_2in attribute table
## contain only NA values and are dropped.